try:
    list1=["python","java","mysql"]
    print(list1[5])
    pass
except Exception as e:
    print("此处发生异常{}".format(e))
    pass
else:
    print("程序执行正常，没有发生错误")
    pass
finally:
    print("无论是否发生异常都会被执行的代码块")

def a():
    print(1/0)
    pass
def b():
    a()
    pass
def c():
    try:
        b()
        pass
    except Exception as e:
        print("分母不能为0")
        pass
    else:
        print("代码正常，没有发生异常")
        pass
c()
# 自定义异常，继承Exception类
class MyException(Exception):
    def __str__(self):
        return "这是一个自定义异常"
    pass
try:
    num=int(input("请输入一个数字"))
    if num>10:
        # raise手动向上抛出异常
        raise MyException
    pass
except MyException as msg:
    print(msg)
    pass
else:
    print("没有出现异常")